import  jwt
import datetime

from django.conf import settings


class JWTTool:
    def getToken(self,userid,account):
        #生成token
        data={
            "userid": userid,
            "account": account,
            "exp": datetime.datetime.now() + datetime.timedelta(hours=1)
        }
        return "Bearer "+jwt.encode(payload=data,key=settings.SECRET_KEY)
    def checkToken(self,token):
        return jwt.decode(token,key=settings.SECRET_KEY,algorithms="HS256")

tooljwt = JWTTool()
# print(tool.getToken(1,"admin"))
# print(tool.checkToken('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOjEsImFjY291bnQiOiJhZG1pbiIsImV4cCI6MTczNDk1NTUwOX0.hRjoaWTfBouwLxksLs7gwrEmamePattFmajApA7W9Go'))
